package com.insigma.yanwenlong.bookkeeping.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.insigma.yanwenlong.bookkeeping.db.jdbc.DBConnection;
import com.insigma.yanwenlong.bookkeeping.pojo.Direction;

public class DirectionDaoImpl implements DirectionDao{

	@Override
	public List<Direction> findDirections() throws SQLException {
		Connection connection = DBConnection.getConnection();
		String sql = "select * from direction";
		Statement statement = connection.createStatement();
		ResultSet resultSet = statement.executeQuery(sql);
		List<Direction> directions = new ArrayList<Direction>();
		while(resultSet.next()) {
			Direction direction = new Direction();
			direction.setId(resultSet.getInt("id"));
			direction.setDirectionName(resultSet.getString("directionName"));
			
			directions.add(direction);
		}
		
		DBConnection.closeResultSet(resultSet);
		DBConnection.closeStatement(statement);
		DBConnection.closeConnection(connection);
		
		return directions;
	}
	
}
